var prefix = "/yw/appraisal";
$(function () {
    validateRule();
});
$.validator.setDefaults({
    submitHandler: function () {
        submit01();
    }
});

function submit01() {
    $.ajax({
        cache: true,
        type: "POST",
        url: prefix + "/item/save",
        data: $('#appraisalForm').serialize(),
        async: false,
        error: function (request) {
            layer.alert("Connection error" + request.message);
        },
        success: function (data) {
            if (data.code === 0) {
                parent.layer.msg("保存成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);

            } else {
                layer.alert(data.msg)
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#appraisalForm").validate({
        rules: {
            appraisalContent: {
                required: true
            },
            money: {
                required: true
            },
            moneyUnit: {
                required: true
            }
        },
        messages: {
            appraisalContent: {
                required: icon + "指标内容不能为空"
            },
            money: {
                required: icon + "金额不能为空"
            },
            moneyUnit: {
                required: icon + "金额标准不能为空"
            }
        }
    })
}